package com.david.avcodec.system

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import androidx.annotation.Nullable
import com.david.avcodec.R

//参考链接：https://blog.csdn.net/yu540135101/article/details/103655058
class SystemAudioActivity: Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_system_audio)
        findViewById<View>(R.id.system_audio_record).setOnClickListener {
            val intent = Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION)
            startActivityForResult(intent, 1)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, @Nullable data: Intent) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK) {
            //请求
            if (requestCode == 1) {
                //得到录音的音频文件及路径
                val dataFile = data.getDataString()
                Log.d("audio", "dataFile: " + dataFile)
            }
        }
    }
}